package com.interest.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.interest.business.domain.PayRecord;
import com.interest.business.service.IPayRecordService;
import com.interest.common.annotation.Log;
import com.interest.common.core.controller.BaseController;
import com.interest.common.core.domain.AjaxResult;
import com.interest.common.core.page.TableDataInfo;
import com.interest.common.enums.BusinessType;
import com.interest.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 下单记录Controller
 * 
 * @author ruoyi
 * @date 2024-04-17
 */
@RestController
@RequestMapping("/business/record")
public class PayRecordController extends BaseController
{
    @Autowired
    private IPayRecordService payRecordService;

    /**
     * 查询下单记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(PayRecord payRecord)
    {
        startPage();
        List<PayRecord> list = payRecordService.selectPayRecordList(payRecord);
        return getDataTable(list);
    }

    /**
     * 导出下单记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:record:export')")
    @Log(title = "下单记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PayRecord payRecord)
    {
        List<PayRecord> list = payRecordService.selectPayRecordList(payRecord);
        ExcelUtil<PayRecord> util = new ExcelUtil<PayRecord>(PayRecord.class);
        util.exportExcel(response, list, "下单记录数据");
    }

    /**
     * 获取下单记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(payRecordService.selectPayRecordById(id));
    }

    /**
     * 新增下单记录
     */
    @PreAuthorize("@ss.hasPermi('business:record:add')")
    @Log(title = "下单记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PayRecord payRecord)
    {
        return toAjax(payRecordService.insertPayRecord(payRecord));
    }

    /**
     * 修改下单记录
     */
    @PreAuthorize("@ss.hasPermi('business:record:edit')")
    @Log(title = "下单记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PayRecord payRecord)
    {
        return toAjax(payRecordService.updatePayRecord(payRecord));
    }

    /**
     * 删除下单记录
     */
    @PreAuthorize("@ss.hasPermi('business:record:remove')")
    @Log(title = "下单记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(payRecordService.deletePayRecordByIds(ids));
    }
}
